package tv.youxing.android.ui;

import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import butterknife.BindView;
import butterknife.ButterKnife;
import tv.youxing.android.R;
import tv.youxing.android.custom.CustomToolbar;
import tv.youxing.android.utils.L;


/**
 * Created by Administrator on 2017/7/26.
 * H5页面
 */

public class AdvertisementWEBActivity extends BaseActivity{


    @BindView(R.id.webview)
    WebView mWebView;
    @BindView(R.id.tb)
    CustomToolbar mCustomToolbar;

    String url;
    String title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_advertisementweb);
        ButterKnife.bind(this);

        url = getIntent().getStringExtra("url");


        if (getIntent().getStringExtra("title") != null) {
            title = getIntent().getStringExtra("title");
        } else {
            title="广告详情";
        }

        mCustomToolbar.setTitle(title);


        loadWEB();
    }


    void loadData() {

    }

    void loadWEB() {

        L.d("url:" + url);
        mWebView.loadUrl(url);


        // 获取WebView属性
        WebSettings websettings = mWebView.getSettings();
        // 设置支持javascript代码
        websettings.setJavaScriptEnabled(true);

        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // 打开地址
                view.loadUrl(url);
                // 返回的是true，代表在webView控件中打开，否则在系统的浏览器中打开
                return true;
            }
        });
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
            mWebView.goBack();// 返回前一个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
